package cn.wit.summit.chwan.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;

import java.util.ArrayList;
import java.util.List;

import pub.devrel.easypermissions.EasyPermissions;

/**
 * Created by Alan on 2018/3/28.
 */

public class PermissionManagerUtil {
    //所有
    public static final String[] PERM_ALL = {
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.REQUEST_INSTALL_PACKAGES
    };
    public static final int RC_ALL_PERM = 3000;
    public static boolean hasAllPermission(Context context) {
//        return EasyPermissions.hasPermissions(context, PermissionManagerUtil.PERM_ALL);
        return true;
    }

    //手机权限
    public static final String[] PERM_PHONE = {
            Manifest.permission.READ_PHONE_STATE
    };
    public static final int RC_PHONE_PERM = 3001;
    public static boolean hasPhonePermission(Context context) {
//        return EasyPermissions.hasPermissions(context, PermissionManagerUtil.PERM_PHONE);
        return true;
    }

    //读写内存权限
    public static final String[] PERM_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE
            , Manifest.permission.WRITE_EXTERNAL_STORAGE};
    public static final int RC_STORAGE_PERM = 3002;
    public static boolean hasStoragePermission(Context context) {
//        return EasyPermissions.hasPermissions(context, PermissionManagerUtil.PERM_STORAGE);
        return true;
    }

    //安装权限
    public static final String[] PERM_INSTALL = {Manifest.permission.REQUEST_INSTALL_PACKAGES};
    public static final int RC_INSTALL_PERM = 3003;
    public static boolean hasInstallPermission(Context context) {
//        return EasyPermissions.hasPermissions(context, PermissionManagerUtil.PERM_INSTALL);
        return true;
    }

    public static boolean checkAndRequestPermiss(Activity activity, int requestCode, String describ, String... premiss) {
        if (EasyPermissions.hasPermissions(activity, premiss)) {
            return true;
        } else {
            boolean hasRefres=false;
            for (String per:premiss){
                if (  ActivityCompat.shouldShowRequestPermissionRationale(activity, per)){
                    hasRefres=true;
                }
            }
            if (hasRefres){

            }
            ActivityCompat.requestPermissions(activity,
                    premiss,
                    requestCode);
//            EasyPermissions.requestPermissions(activity, describ, requestCode, premiss);
            return false;
        }
    }

}
